﻿using PureMVC.Interfaces;
using PureMVC.Patterns.Facade;
using PureMVC.Patterns.Proxy;
using WooEngine.Data.Interfaces;

namespace WooEngine.Data.Base
{
    public abstract class AbstractDataProxy<T, D> : Proxy, IDataProxy<D> where T : IData<D>
    {

        protected bool m_isActivity = false;

        public bool IsActivity { get => m_isActivity; }

        public AbstractDataProxy(string proxyName, T data) : base(proxyName, data)
        {
            m_isActivity = false;
            Facade.RegisterProxy(this);
        }

        public void ReleaseData()
        {
            m_isActivity = false;

            Facade.RemoveProxy(ProxyName);

            GetData().Release();

            Data = null;
        }

        public T GetData()
        {
            return (T)Data;
        }


        public void Initialize(D data)
        {
            GetData().Initialize(data);

            m_isActivity = true;
        }

    }

}
